 //
//  YLMusicTool.m
//  音乐播放器
//
//  Created by 袁量 on 2017/6/5.
//  Copyright © 2017年 袁量. All rights reserved.
//

#import "YLMusicTool.h"
#import "MJExtension.h"
@implementation YLMusicTool
static NSArray *_musics;
static YLMusic*_playingMusic;
+ (void)initialize
{
    if (_musics == nil) {
        _musics = [YLMusic objectArrayWithFilename:@"Musics.plist"]; 
    }
    
    if (_playingMusic == nil) {
        _playingMusic = _musics[1];
    }
}
+ (NSArray *)musics{
    return _musics;
}
+ (YLMusic *)playingMusic{
    return _playingMusic;
}
+ (void)setupPlayingMusic:(YLMusic *)playingMusic
{
    _playingMusic = playingMusic;
}
+ (YLMusic *)previousMusic
{
    // 1.获取当前音乐的下标值
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    // 2.获取上一首音乐的下标值
    NSInteger previousIndex = --currentIndex;
    YLMusic *previousMusic = nil;
    if (previousIndex < 0) {
        previousIndex = _musics.count - 1;
    }
    previousMusic = _musics[previousIndex];
    
    return previousMusic;
}


+ (YLMusic *)nextMusic
{
    // 1.获取当前音乐的下标值
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    // 2.获取下一首音乐的下标值
    NSInteger nextIndex = ++currentIndex;
    YLMusic *nextMusic = nil;
    if (nextIndex >= _musics.count) {
        nextIndex = 0;
    }
    nextMusic = _musics[nextIndex];
    
    return nextMusic;
}
@end
